import { Injectable } from '@angular/core'
import { ObservableStore } from '@shared/classes/ObservableStoreClass'
import { Merchant } from '@shared/interfaces/merchant'
import { GroupCommon } from '@shared/interfaces/group'
import { Terminal } from '@shared/interfaces/terminal'
import { Task } from '@shared/interfaces/task'
import { StoreFull, IQRRouteOfStore, Store, Generadata } from '@shared/interfaces/store'
import { EPaymentBrand } from '@shared/enums'
import { Role, IRoleCreateFormData } from '@shared/interfaces/role'
import { RiskControlScheme, RiskControlRule } from '@shared/interfaces/risk-control'
import { PostRiskScheme, RiskRules, PostRisk } from '@shared/interfaces/post-risk-control'
import { ITrade, ManualTrans } from '@shared/interfaces/trade'
import { User } from '@shared/interfaces/user'
import { from } from 'rxjs'
@Injectable({
  providedIn: 'root'
})
export class DataService {

  public merchant$: ObservableStore<Merchant> = new ObservableStore(new Merchant())
  public group$: ObservableStore<GroupCommon> = new ObservableStore(new GroupCommon())
  public storeFull$: ObservableStore<StoreFull> = new ObservableStore(new StoreFull())
  public terminal$: ObservableStore<Terminal> = new ObservableStore(new Terminal())
  public task$: ObservableStore<Task> = new ObservableStore(new Task())
  public insCode$: ObservableStore<string> = new ObservableStore('')
  /** 用于门店审核中 用户列表的获取 */
  public intStoreCode$: ObservableStore<string> = new ObservableStore('')
  public storeRoute$: ObservableStore<IQRRouteOfStore> = new ObservableStore({
    chanCode: EPaymentBrand.Empty,
    paymentBrand: EPaymentBrand.Empty,
  })
  public role$: ObservableStore<Role> = new ObservableStore(new Role())
  public roleCreateData$: ObservableStore<IRoleCreateFormData> = new ObservableStore({})
  public trade$: ObservableStore<ITrade> = new ObservableStore({} as ITrade)

  public riskControlScheme$: ObservableStore<RiskControlScheme> = new ObservableStore(new RiskControlScheme('1', '1'))
  public riskControlRule$: ObservableStore<RiskControlRule> = new ObservableStore(new RiskControlRule())
  public postRiskScheme$: ObservableStore<PostRiskScheme> = new ObservableStore(new PostRiskScheme('1', '1'))
  public riskRules$: ObservableStore<RiskRules> = new ObservableStore(new RiskRules())
  public user$: ObservableStore<User> = new ObservableStore(new User())
  /** 门店更新token */
  public token$: ObservableStore<string> = new ObservableStore('')

  /** 门店编辑审核用 */
  public origStore$: ObservableStore<Store> = new ObservableStore(new Store())
  public currentStore$: ObservableStore<Store> = new ObservableStore(new Store())
  public isNeedDiff$: ObservableStore<boolean> = new ObservableStore(false)

  /** 事后风控方案编辑审核用 */
  public currentPostRisk$: ObservableStore<PostRiskScheme> = new ObservableStore(new PostRiskScheme())
  public origPostRisk$: ObservableStore<PostRiskScheme> = new ObservableStore(new PostRiskScheme())

  public showShop$: ObservableStore<boolean> = new ObservableStore(true)

  /** 批次请款使用 */
  public batchPresentList$: ObservableStore<ManualTrans[]> = new ObservableStore([])

  constructor() { }

  setInsCode(insCode: string) {
    this.insCode$.setValue(insCode)
  }

  get insCode() {
    return this.insCode$.value
  }

  setIntStoreCode(intStoreCode: string) {
    this.intStoreCode$.setValue(intStoreCode)
  }

  resetIntStoreCode(): void {
    this.intStoreCode$.setValue(null)
  }

  get intStoreCode(): string {
    return this.intStoreCode$.value
  }

  setMerchant(merchant: Merchant) {
    this.merchant$.setValue(merchant)
  }

  get merchant() {
    return this.merchant$.value
  }

  setGroup(group: GroupCommon) {
    this.group$.setValue(group)
  }

  get group() {
    return this.group$.value
  }

  setStoreFull(full: StoreFull) {
    this.storeFull$.setValue(full)
  }

  resetStoreFull() {
    this.storeFull$.setValue(new StoreFull())
  }

  get storeFull() {
    return this.storeFull$.value
  }

  setStoreRoute(chan: IQRRouteOfStore) {
    this.storeRoute$.setValue(chan)
  }

  get StoreRoute() {
    return this.storeRoute$.value
  }

  setTerminal(terminal: Terminal) {
    this.terminal$.setValue(terminal)
  }

  get terminal() {
    return this.terminal$.value
  }

  setTask(task: Task) {
    this.task$.setValue(task)
  }

  resetTask() {
    this.task$.setValue(new Task())
  }

  get task() {
    return this.task$.value
  }

  setRole(role: Role) {
    this.role$.setValue(role)
  }

  get role() {
    return this.role$.value
  }

  setRoleCreateData(role: IRoleCreateFormData) {
    this.roleCreateData$.setValue(role)
  }

  get roleCreateData() {
    return this.roleCreateData$.value
  }

  setRiskControlScheme(scheme: RiskControlScheme) {
    this.riskControlScheme$.setValue(scheme)
  }

  get riskControlScheme() {
    return this.riskControlScheme$.value
  }

  setRiskControlRule(rule: RiskControlRule) {
    this.riskControlRule$.setValue(rule)
  }

  get riskControlRule() {
    return this.riskControlRule$.value
  }

  sePostRiskScheme(scheme: PostRiskScheme) {
    this.postRiskScheme$.setValue(scheme)
  }

  get postRiskScheme() {
    return this.postRiskScheme$.value
  }

  serRiskRules(rule: RiskRules) {
    this.riskRules$.setValue(rule)
  }

  get riskRules() {
    return this.riskRules$.value
  }

  setTrade(trade: ITrade) {
    this.trade$.setValue(trade)
  }

  resetTrade(): void {
    this.trade$.setValue({} as ITrade)
  }

  get trade(): ITrade {
    return this.trade$.value
  }

  setUser(user: User) {
    this.user$.setValue(user)
  }

  get user(): User {
    return this.user$.value
  }

  setToken(token: string) {
    this.token$.setValue(token)
  }

  resetToken(): void {
    this.token$.setValue('')
  }

  get token(): string {
    return this.token$.value
  }

  setOrigStore(store: Store) {
    this.origStore$.setValue(store)
  }

  resetOrigStore(): void {
    this.origStore$.setValue(new Store())
  }

  get origStore(): Store {
    return this.origStore$.value
  }

  setCurrentStore(store: Store) {
    this.currentStore$.setValue(store)
  }

  resetCurrentStore(): void {
    this.currentStore$.setValue(new Store())
  }

  get currentStore(): Store {
    return this.currentStore$.value
  }

  setCurrentPostrisk(postRiskScheme: PostRiskScheme) {
    this.currentPostRisk$.setValue(postRiskScheme)
  }

  resetCurrentPostrisk(): void {
    this.currentPostRisk$.setValue(new PostRiskScheme())
  }

  get currentPostrisk(): PostRiskScheme {
    return this.currentPostRisk$.value
  }

  setOrigPostrisk(postRiskScheme: PostRiskScheme) {
    this.origPostRisk$.setValue(postRiskScheme)
  }

  resetOrigPostrisk(): void {
    this.origPostRisk$.setValue(new PostRiskScheme())
  }

  get origPostrisk(): PostRiskScheme {
    return this.origPostRisk$.value
  }

  setIsNeedDiff(isNeed) {
    this.isNeedDiff$.setValue(isNeed)
  }

  resetIsNeedDiff(): void {
    this.isNeedDiff$.setValue(false)
  }

  get isNeedDiff(): boolean {
    return this.isNeedDiff$.value
  }

  setBatchPresentList(list: ManualTrans[]) {
    this.batchPresentList$.setValue(list)
  }

  get batchPresentList() {
    return this.batchPresentList$.value
  }

  get showShopId() {
    return this.showShop$.value
  }

  setShowShopId(value)   {
    this.showShop$.setValue(value)
  }
}
